	import {useStore} from "vuex";
	import { RefundAuditListDetail, RefundAudit,RefundAuditLast} from "../../api/refundaudit"
	export function useRefundAuditListDetail(){
		const {state} = useStore()
		function initRefundAuditListDetail(JFD_ID:string){
			return new Promise((resolve, reject)=>{
				RefundAuditListDetail({  //获取审核详情
					JFD_ID:JFD_ID,
					OPERATOR_ID:state.user.userInfo.CUSER_ID
				})
				.then(res=>{
					if (res.ERROR[0].errcode == '0'){
					    resolve(res)
					}else {
					    uni.showToast({
					        title: res.ERROR[0].error,
					        icon: 'none',
					        mask: true
					    })
					    reject('err')
					}
				})
				.catch(err=>{
					uni.showToast({
					    title: '获取列表失败',
					    icon: 'error',
					    mask: true
					})
					reject('err')
				})
			})
		}
		function initRefundAudit(params:any){
			return new Promise((resolve,reject)=>{
				RefundAudit({  //提交审核信息
					JFD_ID:params?.JFD_ID,
					SH_FLAG:params?.SH_FLAG,
					OPERATOR_ID:state.user.userInfo.CUSER_ID
				}).then(res=>{
					if (res.ERROR[0].errcode == '0'){
					    resolve(res)
					}else {
					    uni.showToast({
					        title: res.ERROR[0].error,
					        icon: 'none',
					        mask: true
					    })
					    reject('err')
					}
				})
				.catch(err=>{
					uni.showToast({
					    title: '提交审核失败',
					    icon: 'error',
					    mask: true
					})
					reject('err')
				})
			})
		}
		function initRefundAuditLast(params:{
			total_fee:string,
			order_code:string,
			transaction_id:string
		}){
			return new Promise((resolve,reject)=>{
				RefundAuditLast({  //审核成功执行退款
					total_fee:params?.total_fee,
					order_code:params?.order_code,
					transaction_id:params?.transaction_id,
                    OPERATOR_ID: state.user.userInfo.CUSER_ID
				})
				.then(res=>{
					if (res.result_code == "SUCCESS"){
					  uni.showToast({
					      //title: "退款成功",
						  title: "退款审核完成!",
					      icon: 'none',
					      mask: true
					  })
						setTimeout(()=>{
							uni.navigateBack({
								delta: 1
							})
						},2500)
					}else {
						uni.showToast({
								title: res.ERROR[0].error,
								icon: 'none',
								mask: true
						})
						reject('err')
					}
				})
				.catch(err=>{
					uni.showToast({
					    title: '退款失败',
					    icon: 'error',
					    mask: true
					})
					reject('err')
				})
			})
		}
		return{
			initRefundAuditListDetail,
			initRefundAudit,
			initRefundAuditLast
		}
	}